package four;

import java.util.*;
public class A067 {


    Stack<Integer> stack;
    Stack<Integer> minStack;
//    public MinStack() {
//        minStack = new Stack<>();
//        stack = new Stack<>();
//    }

    public void push(int val) {
        stack.push(val);
        if(minStack.isEmpty()) {
            minStack.push(val);
        }else {
            int top = minStack.peek();
            if(val <= top) {
                minStack.push(val);
            }
        }
    }

    public void pop() {
        if(stack.isEmpty()) return;
        int val = stack.pop();
        if(val == minStack.peek()) {
            minStack.pop();
        }
        //return val;
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}
